#!/usr/bin/perl -w
use strict;

use Encode(qw(decode));
my $tools_path = $ENV{'tools_path'};
my $lib = $tools_path . '/perl_module/Spreadsheet-WriteExcel-2.40/lib';
push (@INC, $lib);


# my $pm = $tools_path . "/" . "perl_module/Spreadsheet-WriteExcel-2.40/lib";
# use lib $pm;

use Spreadsheet::WriteExcel;




my $out_file = $ARGV[$#ARGV];
my $workbook  = Spreadsheet::WriteExcel -> new($out_file);

my @sheets= ("summary", "high-confidence variants", "low-confidence variants", "false-positive variants");


# foreach my $sheet (@sheets) {
	# my $worksheet = $workbook->add_worksheet($sheet);
	# my $file_name = $ARGV[0];
	# open (CVS, $file_name) or die "$!";
# }

my ($worksheet, $file_name, $row);
foreach my $i (0..($#ARGV-1)) {
	$worksheet = $workbook->add_worksheet($sheets[$i]);
	$file_name = $ARGV[$i];
	open (CVS, $file_name) or die "$!";
	
	$row = 0;
	while (<CVS>) {
        chomp;
        my @Fld = split('\t', $_);
        my $col = 0;
        foreach my $token (@Fld) {
                $worksheet->write_string($row, $col, decode('gb2312',$token));
                $col++;
        }
        $row++;
	}

}

# my $worksheet_1 = $workbook->add_worksheet("summary");
# my $file_name = $ARGV[0];
# open (CVS, $file_name) or die "$!";
# my $row = 0;
# while (<CVS>) {
        # chomp;
        # my @Fld = split('\t', $_);
        # my $col = 0;
        # foreach my $token (@Fld) {
                # $worksheet_1->write_string($row, $col, decode('gb2312',$token));
                # $col++;
        # }
        # $row++;
# }


# my $worksheet = $workbook->add_worksheet("high-confidence variants");
# $file_name = $ARGV[1];
# open (CVS, $file_name) or die "$!";
# $row = 0;
# while (<CVS>) {
        # chomp;
        # my @Fld = split('\t', $_);
        # my $col = 0;
        # foreach my $token (@Fld) {
                # $worksheet->write_string($row, $col, decode('gb2312',$token));
                # $col++;
        # }
        # $row++;
# }


# my $worksheet1 = $workbook->add_worksheet("low-confidence variants");
# $file_name = $ARGV[2];
# open (CVS, $file_name) or die "$!";
# $row = 0;
# while (<CVS>) {
        # chomp;
        # my @Fld = split('\t', $_);
        # my $col = 0;
        # foreach my $token (@Fld) {
                # $worksheet1->write_string($row, $col, decode('gb2312',$token));
                # $col++;
        # }
        # $row++;
# }


# my $worksheet2 = $workbook->add_worksheet("putative false-positive calls");
# $file_name = $ARGV[3];
# open (CVS, $file_name) or die "$!";
# $row = 0;
# while (<CVS>) {
        # chomp;
        # my @Fld = split('\t', $_);
        # my $col = 0;
        # foreach my $token (@Fld) {
                # $worksheet2->write_string($row, $col, decode('gb2312',$token));
                # $col++;
        # }
        # $row++;
# }

$workbook->close();




